﻿using System;
using System.Collections.Generic;

class Program
{
    static void Subtract(decimal[] firstPolinom, decimal[] secondPolinom, decimal[] result)
    {
        int minLength = 0;
        int smallerPolinom = 0;

        if (firstPolinom.Length < secondPolinom.Length)
        {
            minLength = firstPolinom.Length;
            smallerPolinom = 1;
        }
        else
        {
            minLength = secondPolinom.Length;
            smallerPolinom = 2;
        }
        for (int i = 0; i < minLength; i++)
        {
            result[i] = firstPolinom[i] - secondPolinom[i];
        }
        for (int i = minLength; i < result.Length; i++)
        {
            if (smallerPolinom == 1)
            {
                result[i] = secondPolinom[i];
            }
            else if (smallerPolinom == 2)
            {
                result[i] = firstPolinom[i];
            }
        }

    }
    static void Multiplycation(decimal[] firstPolinomial, decimal[] secondPolinomial, decimal[] result)
    {

        for (int i = 0; i < result.Length; i++)
        {
            result[i] = 0;
        }

        for (int i = 0; i < firstPolinomial.Length; i++)
        {
            for (int j = 0; j < secondPolinomial.Length; j++)
            {
                int position = i + j;
                result[position] += (firstPolinomial[i] * secondPolinomial[j]);
            }
        }
    }

    static void PrintPolynom(decimal[] result)
    {
        for (int i = result.Length - 1; i >= 0; i--)
        {
            if (result[i] != 0 && i != 0)
            {
                if (result[i - 1] >= 0)
                {
                    Console.Write("{1}^x{0} +", i, result[i]);
                }
                else
                {
                    Console.Write("{1}^x{0} ", i, result[i]);
                }
            }
            else if (i == 0)
            {
                Console.WriteLine("{0}", result[i]);
            }

        }
    }
    static void Main(string[] args)
    {
        decimal[] firstPolynom = { 5, 0, 1 };
        decimal[] secPolynom = { 6, 3 };

        int maxLength = 0;
        if (firstPolynom.Length > secPolynom.Length)
        {
            maxLength = firstPolynom.Length;
        }
        else
        {
            maxLength = secPolynom.Length;
        }

        decimal[] result = new decimal[maxLength];
        Subtract(firstPolynom, secPolynom, result);
        PrintPolynom(result);

        decimal[] resmultiply = new decimal[firstPolynom.Length + secPolynom.Length];

        Multiplycation(firstPolynom, secPolynom, resmultiply);
        PrintPolynom(resmultiply);


    }
}

